<%@page import="com.kensure.shike.constant.BusiConstant"%>
<%@page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>三1节抽奖</title>
	<meta http-equiv="Content-Type" content="textml; charset=UTF-8">
	<script type="text/javascript" src="<%=BusiConstant.context%>/common/js/jquery.min.js"></script>
	<script type="text/javascript" src="<%=BusiConstant.context%>/common/js/jquery.cookie.js"></script>
	<script type="text/javascript" src="<%=BusiConstant.context%>/common/base.js?ver=<%=BusiConstant.version%>"></script>
	<script type="text/javascript" src="<%=BusiConstant.context%>/common/http.js?ver=<%=BusiConstant.version%>"></script>
		
</head>
<style>
	*{padding:0; margin:0;}
	body{
	background:url('<%=BusiConstant.context%>/page1/webview/nianhui/img/bg.jpg') no-repeat;
	background-size:cover;
	}
	.container{width:600px; height:200; position:fixed; top:50%; left:45%; margin:-100px 0 0 -200px; text-align:center; }
	.result-box{ background-color:#fff; text-align:center; line-height:60px; font-size:34px;}
	.result-box2{ background-color:#fff; text-align:center; line-height:60px; font-size:34px;}
	button{ width:200px; height:50px; line-height:50px; margin-top:30px; border:none; color:#fff; font-size:24px;}
	button:focus{outline:none;}
	.start{ background-color:#428bca;}
	.end{ background-color:#d9534f;}
</style>
<body>
	<div class="container">
			<div class="result-box2" id="title">
				
			</div>
		
		<div class="result-box">
			000****0000
		</div>
		<button class="start" onClick="start()">开始抽奖</button>
	</div><!--container-->
	<select onchange="changehtml(this)" id="jiangxiang">
	</select>
	<script type="text/javascript">
		var choujiangdata=[];//参与人员
		//内定中奖人员
		var initP=[];
		var p1Winner=new Array(); //一等奖中奖者
		var p2Winner=new Array(); //二等奖中奖者
		var p3Winner=new Array(); //三等奖中奖者
		var btn=true; //按钮状态未开始还是结束
		var key=0; //中奖下标
		var time=0; //定时器

		function runTime(){
			//$("button").show();
			clearInterval(time);
			time=setInterval('trunNum()',10);
		}
		
		function changehtml(){
			var selectVal = $("#jiangxiang option:selected").val();
			var guige = null;
			for(var i=0;guigelist.length>i;i++){
				var temp = guigelist[i];
				if(temp.id == selectVal){
					guige = temp;
				}
			}
			
			$("#title").html(guige.name+"<br>"+guige.remark);
		}
		
		
		//点击按钮
		var issending = false;
		function start(){
			if(btn){
				btn=false;
				$("button").removeClass("start").addClass("end").text("结束抽奖");
				startTrun();		
			}else{
				if(issending){
					alert("请不要重复点击");
				}
				
				btn=true;
				issending = true;
				$("button").removeClass("end").addClass("start").text("开始抽奖");
				endTrun();
			}
		}

		function trunNum(){
			key=Math.floor(Math.random()*(choujiangdata.length));
			var infoo = choujiangdata[key];
			showrow(infoo);
		}
		
		//开始转动数字
		function startTrun(){
			runTime();
		}

		//停止转动数字
		function endTrun(){
			savebaobei($("select").val());
		}
		
		function showrow(infoo){
			var tel1 = infoo.phone;
			if(infoo.phone && infoo.phone.length > 7){
				tel1=infoo.phone.toString().substr(0, 3)+'****'+infoo.phone.toString().substr(7);
			}
			var tel=infoo.userid+"-"+tel1+"-"+infoo.name;
			$(".result-box").text(tel);
		}
		
		function endshow(infoo){
			clearInterval(time);
			var tel1 = infoo.phone;
			if(infoo.phone && infoo.phone.length > 7){
				tel1=infoo.phone.toString().substr(0, 3)+'****'+infoo.phone.toString().substr(7);
			}
			var tel= "恭喜："+infoo.userid+"-"+tel1+"-"+infoo.name+"中奖";
			$(".result-box").text(tel);
		}
		
	</script>
</body>

<script>
var basecontext = '<%=BusiConstant.context%>';
function getList(){
	var url = getbaseurl("/cj/bmlist.do");
	postdo(url, {}, function(data){
		choujiangdata = data.resultData.rows;
	}, null, null);
}
getList();

var guigelist = [];
function getList2(){
	var url = getbaseurl("/cj/gglist.do");
	postdo(url, {cjid:1}, function(data){
		guigelist = data.resultData.rows;
		for(var i=0;guigelist.length>i;i++){
			var item = guigelist[i];
			$("#jiangxiang").append(new Option(item.name, item.id));// 下拉菜单里添加元素
		}
		changehtml();
	}, null, null);
}
getList2();

function savebaobei(guigeid){
	var url = getbaseurl("/cj/choujiang.do");
	var data = {guigeid:guigeid};
	postdo(url, data, function(data){
		var row = data.resultData.row;
		for(var i = 0;choujiangdata.length>i;i++){
			var cdata = choujiangdata[i];
			if(cdata.id == row.id){
				endshow(cdata);
				choujiangdata.splice(i,1);
				break;
			}		
		}
		issending = false;
	}, null, null);
}




</script>

</html>
